<?php

namespace JsonLowCode\UI;

use Closure;
use JsonLowCode\Schema;
use JsonLowCode\Traits\Props\HasAlignText;

/**
 * Ul标签
 * @method static Ul make(Closure $children = null, string $as = "Ul") Ul组件
 */
class Ul extends Schema
{
    use HasAlignText;

    protected array $items = [];

    /**
     * @param Closure|null $children
     * @param string $as "Ul", "Ol"
     */
    public function __construct(Closure $children = null, string $as = "Ul")
    {
        parent::__construct();
        $this->componentName('N'.$as);
        $this->children($children);
    }

    public function li(mixed $children): El
    {
        $el = new El($children);
        $el->componentName("NLi");
        $this->items[] = $el;
        return $el;
    }

    public function jsonSerialize(): array
    {
        foreach ($this->items as $item){
            $this->children($item);
        }
        return $this->toArray();
    }
}
